#include <sys/socket.h>
#include <arpa/inet.h>
#include <error.h>
#include <stdlib.h>
#include <stdio.h>
#include "../ftp.h"

#define ARGS_CHECK(argc,expect){if(argc!=expect){printf("ARGC NUM IS WRONG!\n");exit(-1);}}

int main(int argc, char *argv[])
{
    // ./client 192.168.159.128 12345 a
    ARGS_CHECK(argc,4);
    int sockfd=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in addr;
    addr.sin_family=AF_INET;
    addr.sin_addr.s_addr=inet_addr(argv[1]);
    addr.sin_port=htons(atoi(argv[2]));
    if(connect(sockfd,(struct sockaddr*)&addr,sizeof(addr))==-1){
        perror("connect");
        return -1;
    }

    if(recv_file(sockfd,argv[3])==-1){
        perror("recv_file");
        return -1;
    }

    return 0;
}
